package lib

import "algorithms/ds"

func init() {
	Probs = append(Probs, Problem{
		Num:         83,
		Discription: "删除链表中的重复元素",
		Level:       1,
		Labels: map[string]int{
			"链表":   1,
			"快慢指针": 1,
		},
	})
}

func DeleteDuplicates2(head *ds.ListNode) *ds.ListNode {
	if head == nil {
		return nil
	}

	slow := head
	fast := head.Next
	for fast != nil {
		if slow.Val != fast.Val {
			slow.Next = fast
			slow = slow.Next
		}

		fast = fast.Next
	}

	slow.Next = nil
	return head
}
